{include file="../app/view/common/header.html" subtitle="抽奖机" page="lucky"}

<div class="mdui-textfield">
    <input class="mdui-textfield-input" type="number" placeholder="个数" style="width: 40%;display: inline;" id="p"/>
    <button class="mdui-btn mdui-color-theme-accent mdui-ripple" style="left: 1%;width: 10%;" onclick="begin()">开始抽奖！</button>
    <h1 id="lucky"></h1>
</div>
<div class="mdui-table-fluid">
    <table class="mdui-table mdui-table-hoverable mdui-table-selectable">
      <thead>
        <tr>
          <th>#</th>
          <th>姓名</th>
          <th>分组</th>
        </tr>
      </thead>
      <tbody id="table">
        
      </tbody>
    </table>
  </div>
<script>
    table = document.getElementById("table")
    var sub = `<tr name="REALNAME">
            <td>ID</td>
            <td>REALNAME</td>
            <td>GROUP</td>
            </tr>`
</script>
<script src="/static/user/list.js"></script>
<script>
    function begin() {
        s = ""
        d = document.getElementsByClassName("mdui-table-row-selected")
        n = d.length
        m = document.getElementById("p").value
        if (n<m) {error_bar("抽太多啦，要死循环的");return} 
        
        while(m--) {
            j = Math.floor(Math.random()*n)
            if (s.indexOf(d[j].getAttribute("name")) != -1) {++m;continue} // 排除重复
            s += d[j].getAttribute("name")+"、"
        }
        document.getElementById("lucky").innerHTML = "恭喜："+s+"中奖！"
    }
</script>